﻿using System;
using viBlog.Controllers;
using visinia.SmartEngine.Site;

public partial class Admin_Pages_viBlog_BlogSettings_BlogSettings : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BLOG_NAME.Text = BlogController.BlogName;
            TAG_LINE.Text = BlogController.BlogTagLine;
            if (SiteSettings.FrontPage == BlogController.BlogPageId)
                HOMEPAGE.Checked = true;
            POSTS_PER_PAGE.Text = BlogController.PostsCountPerPage.ToString();
            SYNDICATE_POSTS_COUNT.Text = BlogController.PostsCountToSyndicate.ToString();
            COMMENT_MODERATION.Checked = BlogController.ModerateComments;
        }
    }
    public void Save()
    {
        BlogController.BlogName = BLOG_NAME.Text;
        BlogController.BlogTagLine = TAG_LINE.Text;
        if (HOMEPAGE.Checked)
            SiteSettings.FrontPage = BlogController.BlogPageId;
        int count = 0;
        if (Int32.TryParse(POSTS_PER_PAGE.Text, out count))
        {
            if (count < 5)
            {
                count = 5;
                POSTS_PER_PAGE.Text = "5";
            }
            BlogController.PostsCountPerPage = count;
            BlogController.ModerateComments = COMMENT_MODERATION.Checked;
        }
        int countSyndicate = 0;
        if (Int32.TryParse(SYNDICATE_POSTS_COUNT.Text, out countSyndicate))
            BlogController.PostsCountToSyndicate = countSyndicate;
    }
}
